home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / jmodem.arc / JMODEM.XYW < prev    next >
Encoding:
Text File  |  1988-09-13  |  9.8 KB  |  153 lines

  1. «LM10»«RM70»«PL56»«FD63»«RFA«FC»- «PN» -
  2. «FL» »
  3. «FC»J M O D E M
  4. File Transfer System
  5. Compliments of
  6.  Richard B. Johnson
  7. PROGRAM EXCHANGE
  8. (719) 548-0108
  9. «DA»
  10. «FL»
  11. General:
  12. First Let me get this over with.
  13. MS-DOS is a registered trademark of Microsoft Corporation
  14. IBM, IBM-PC, IBM-XT, AT, are registered trademarks of International Business Machines, Inc. WILDCAT! is a trademark of Mustang Software. XMODEM is a public-domain file-transfer protocol developed by Ward Christensen.
  15.  
  16. JMODEM is released into the public domain. As with most public-domain protocols, you are advised that there is no implied warranty of any kind. The source-code is provided so that you may determine for yourself if this program may serve a useful purpose. It is written in Microsoft MASM Assembly-language using good standards of engineering practice. It does not use any strange or "undocumented" functions of the MS-DOS operating system.
  17.  
  18.     PLEASE UPLOAD THIS FILE (The ARC file) to as many
  19.     BBS systems as you can so that it gets installed
  20.     all around the country.
  21.  
  22. Introduction:
  23. JMODEM is a new file-transfer protocol developed to be used as an "external protocol" on BBS systems and personal computers using the IBM-PC/AT/XT structure and the MS-DOS operating system.
  24.  
  25. This file-transfer system features:
  26.  
  27.     o    16-bit CRC for verification
  28.     o    File size is exactly maintained
  29.     o    Data compression.
  30.     o    Rapid host/remote synchronization.
  31.     o    Variable-length transmission blocks which,
  32.         if there are few errors, increase to 8192
  33.         data-bytes in length.
  34.     o    Flow control (automatic)
  35.     o    Hangup protection
  36.     o    Aborted files are saved
  37.     o    Files being overwritten are renamed to
  38.         ".OLD", rather than deleted.
  39.     o    COM1 / COM2 support.
  40.     o    Interrupt on received characters allows data
  41.         to be received while the previous block is
  42.         being written to disk. This provides almost
  43.         continuous data transmission without long
  44.         waits between blocks.
  45.  
  46. JMODEM is not for everyone! It does not have any pretty screens to dazzle the user. It is designed to maximize the amount of data that can be transferred in a given time (and reduce telephone cost). It does this by sending very long blocks of data and encoding (compressing) the data wherever possible. Since long blocks of data are subject to many transmission errors, a 16 bit CRC is used to determine the data integrity. As many as ten retries are made if the data is not correctly received. If you have a noisy telephone circuit, you will find that JMODEM will abort more often than the XMODEM protocol which sends very short blocks. A future version that will be downward-compatible with the existing version is being developed that will do "heroic" retries and will even go down to a 16-byte block-lengths if that's what is necessary to get the data transferred.
  47.  
  48. Once synchronization between the remote computer and the host are established, JMODEM paints a status block on the screen that shows how the file transfer is going. The status screen shows the block being transmitted (or the last received), the length of the block, and the total bytes having been transmitted (or received). A special synch~ronization routine is used so that the first block is not thrown away as happens so often in XMODEM type routines. During the synchronization routine, where the host is waiting for the user to enter the proper file parameters (a 30 second wait).  You can abort immediately by sending a control X (^X). After actual file transfer begins, ie. when you see the status window on the screen, no input from the keyboard is possible. You send a control BREAK to abort the transmission (or ^C). In this case, the program will abort after the block being sent/received is complete. This could take 15 or more seconds with long blocks so be patient.
  49.  
  50. In the event that carrier is lost (the user disconnected), the file-transfer program will also abort. This, too, could take as long as 15 seconds.
  51.  
  52. How it works:
  53. The block size starts out at 512 bytes (or the actual bytes in the file -- whichever is less). To this is added a 6-byte overhead. If the block transfer occurred without any retries, the block length is increased by 512 bytes to 1024 bytes. As long as the transmission was successful without incurring any re-tries, the block-length increases to a maximum of 8192 bytes. There is still the same 6-byte overhead so the maximum block length will actually be 8198 bytes. Any time there are retries, the block length (on the next new string) is decreased by 512 bytes. The string-length is never reduced to less than 512 bytes due to errors. When the last bytes are read from the file, the block length may be as little as 7 bytes (one data byte, plus the 6 byte overhead). The file size as received will be exactly the file size as transmitted. XMODEM will "round-up" the file size to the next higher block. This means that MS-DOS's COMP (compare) will always fail when you attempt to check files that have been sent by XMODEM and many other protocols.
  54.  
  55. When the file is read, an attempt is made to compress the data using the well-known RLL process where multiple bytes are compressed into a 4-byte statement.
  56.  
  57. For instance a string that looks like this (hex):
  58.     A0 A0 A0 A0 A0 A0 A0 A0 A0 A0 A0 A0 A0 A0 A0 A0
  59. Gets compressed into this:
  60.     BB 0F 00 A0
  61.      |  |  |  |__________ Byte to repeat
  62.        |  |  |_____________ High byte of repeat length
  63.        |  |________________ Low byte of repeat length
  64.        |___________________ Sentinel Byte
  65.  
  66. The sentinel-byte (BBH), when encountered in a data stream will get expanded to four bytes. Therefore, it is possible for the "compressed" data string to actually be longer than the original. If this occurs, the original string is sent rather than the longer encoded one. Since the kind of data sent can be different from block-to-block, it is necessary to send a control-byte along with the data so the receiver had determine how to operate on the data.
  67.  
  68. This is the control structure:
  69.  
  70. 00 02 00 0B 01 02 03 04 05 06 07 08 09 0A .... 0A EA
  71.  |  |  |  |  |                                 |  |_ CRC
  72.  |  |  |  |  |                                 |____ CRC
  73.  |  |  |  |  |______________________________________ data
  74.  |  |  |  |_________________________________________ rec.
  75.  |  |  |____________________________________________ control
  76.  |  |_______________________________________________ length
  77.  |__________________________________________________ Length
  78.  
  79. Two bytes are used for the string length and two bytes are used for the CRC. As is standard in memory, the high-byte looks "to people using DEBUG" swapped with the low byte. The data is transmitted exactly as the memory image.
  80.  
  81. The length (a word) begins the string so the receiver may know exactly how may bytes to receive.
  82.  
  83. The control byte is bit-mapped to 8 possibilities. The ones most important are:
  84.  
  85.         NORMAL DATA
  86.         COMPRESSED DATA
  87.         END OF FILE
  88.         ABORT
  89.  
  90. This is now the receiver "knows" what to do with the data.
  91.  
  92. The CRC is generated using this polynomial:
  93.  
  94. X =  X + X^(2(n-mod 7).......  Where n = t(n-1)
  95.                  And t = string length
  96.  
  97. It has the advantage of simplicity in assembly-language programming and will detect errors with a probability of about  one undetected error in 2^132 (which is a very large number). It does not correct errors so its not important to use some "standard" function to generate the CRC.
  98.  
  99. Usage:
  100. This program uses parameters on the command line.
  101.  
  102. JMODEM S <filename.typ>    ( Sends a file to COM1:)
  103. JMODEM R <filename.typ>    ( Receives a file from COM1:)
  104. JMODEM S1 <filename.typ>    ( Sends a file to COM1:)
  105. JMODEM R1 <filename.typ>    ( Receives a file from COM1:)
  106. JMODEM S2 <filename.typ>    ( Sends a file to COM2:)
  107. JMODEM R2 <filename.typ>    ( Receives a file from COM2:)
  108.  
  109. Support for COM3 and COM4 have been added on revision level V1.05 . Note that the standards for port locations are de-facto standards only and may not be the ports actually used in your computer. Please modify the communications port structures at the beginning of the assembly-language program to match your system parameters if they are different. The modifications should be done to the STRUCTURES, not to the EQUATES!
  110.  
  111.  
  112. In a batch file, <filename.typ> may be a substitution character.
  113. JMODEM S2 %1            ( Sends a file to COM2:)
  114. JMODEM R2 %1            ( Receives a file from COM2:)
  115.  
  116. How to set up batch files to use this program:
  117. If you are using PCPLUS (PROCOMM +), the batch files should be set up like this:
  118.  
  119. (JDOWN.BAT)
  120. JMODEM R1 %1            ( Download from COM1:)
  121.  
  122. (JUP.BAT)
  123. JMODEM S1 %1            ( Upload to COM1:)
  124.  
  125. If you are running a WILDCAT! bulletin board, the external protocol files should be set up like this:
  126.  
  127. (JUP.BAT)
  128. CD D:\WILDCAT\PROTOCOL
  129. IF EXIST TRANSFER.BAD DEL TRANSFER.BAD
  130. JMODEM R1 %3
  131. IF ERRORLEVEL 1 GOTO END
  132. COPY %3 %4
  133. :END
  134. DEL %3
  135.  
  136. (JDOWN.BAT)
  137. CD D:\WILDCAT\PROTOCOL
  138. IF EXIST TRANSFER.BAD DEL TRANSFER.BAD
  139. JMODEM S1 %3
  140. IF ERRORLEVEL 1 GOTO BAD
  141. GOTO END
  142. :BAD
  143. COPY ALL.OK TRANSFER.BAD
  144. :END
  145.  
  146. JMODEM does not require any information about handshaking. It will look at the modem port and figure out for itself what to do.
  147.  
  148. In the event that the modem carrier is lost, JMODEM will abort. Since JMODEM only checks the modem port occasionally, it may take several seconds to abort when the carrier is lost. It is impossible for a user to get at the DOS level through JMODEM. Do NOT use the CTTY command in the external protocol batch files. JMODEM returns ERRORLEVEL 1 if there was any error in transmission or reception. It returns ERRORLEVEL 0 (no error) otherwise. It does not delete files that have been partially received although it properly closes them. The system operator can arrange the batch files to delete them if required.
  149.  
  150. When JMODEM attempts to create a file that already exists it can't ask the user if the old one should be deleted since the user is probably not in a terminal program at the time. Therefore, JMODEM renames the other file to <filename.OLD> and creates the new file.
  151.  
  152. - Finis -
  153.